package com.yiwyn.Structural.bridge;

/**
 * 桥接模式demo
 */
public class BridgeDemo {


    /**
     * 构建不同的二手车
     */
    public static void main(String[] args) {
        RedColor redColor = new RedColor();
        OneCar oneCar = new OneCar(redColor);
        oneCar.showCarInfo();

        BuleColor buleColor = new BuleColor();
        TwoCar twoCar = new TwoCar(buleColor);
        twoCar.showCarInfo();
    }

    /**
     * 车辆
     */
    public static abstract class Car {
        private final Color color;

        public Car(Color color) {
            this.color = color;
        }

        protected String info() {
            return "车";
        }

        public void showCarInfo() {
            System.out.println(color.getColor() + this.info());
        }
    }

    /**
     * 颜色
     */
    public static abstract class Color {

        public Color() {

        }

        public String getColor() {
            return "颜色";
        }
    }

    // -------------------------- 使用 --------------------------------------

    /**
     * 二手车
     */
    public static class TwoCar extends Car {

        public TwoCar(Color color) {
            super(color);
        }

        @Override
        protected String info() {
            return "二手车";
        }
    }

    /**
     * 一手车
     */
    public static class OneCar extends Car {

        public OneCar(Color color) {
            super(color);
        }

        @Override
        protected String info() {
            return "一手车";
        }
    }

    /**
     * 颜色实例-红色
     */
    public static class RedColor extends Color {

        @Override
        public String getColor() {
            return "寰宇红";
        }
    }

    /**
     * 颜色实例-蓝色
     */
    public static class BuleColor extends Color {

        @Override
        public String getColor() {
            return "星际蓝";
        }
    }

}
